﻿using MiniFox.Utility;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Xml.Serialization;

namespace MiniFox.Platform.Applications.Models
{
    /// <summary>
    /// 系统帐户
    /// </summary>
    [JsonObject]
    public class SystemUser
    {
        //OpenAuthIdentity _identity;
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="identity"></param>
        //public SystemUser(OpenAuthIdentity identity)
        //{
        //    _identity = identity;
        //}
        ///// <summary>
        ///// 
        ///// </summary>
        //[JsonIgnore]
        //[XmlIgnore]
        //public OpenAuthIdentity Identity
        //{
        //    get { return _identity; }
        //}
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("userId")]
        public string UserID
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("displayName")]
        public string DisplayName
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("signName")]
        public string SignName
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("secEmail")]
        public string SecEmail
        {
            get;
            set;
        }
        /// <summary>
        /// 注册手机号(由于隐私问题，不可序列化及反序列化)
        /// </summary>
        [JsonProperty("cellphone")]
        public virtual string Cellphone
        {
            get;
            set;
        }
        /// <summary>
        /// 头像地址
        /// </summary>
        [JsonProperty("icon")]
        public string Icon
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("status"), JsonConverter(typeof(StringEnumConverter))]
        public IdentityStatus Status
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("settings")]
        public UserSettings Settings { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class UserSettings
    {

        /// <summary>
        /// 其它配置数据
        /// </summary>
        public JToken Data { get; set; }

        /// <summary>
        /// 时区代码 如："UTC"、 "China Standard Time"
        /// </summary>
        [Display(Name = "时区")]
        public string TimeZoneID { get; set; }

        /// <summary>
        /// 区域代码 如："zh-CN"、 "en-US"、 "en-UK"
        /// </summary>
        [Display(Name = "地区")]
        public string RegionCode { get; set; }

        /// <summary>
        /// 获取用户特定时区信息
        /// </summary>
        [JsonIgnore]
        [XmlIgnore]
        public TimeZoneInfo UserTimeZone => TimeZoneInfo.FindSystemTimeZoneById(this.TimeZoneID);

        /// <summary>
        /// 获取用户特定区域信息
        /// </summary>
        [JsonIgnore]
        [XmlIgnore]
        public RegionInfo UserRegion => new RegionInfo(this.RegionCode);
    }
}
